package com.data.basic.chapter04;

import com.data.basic.chapter03.ArrayStack;
import com.data.basic.chapter03.MyStack;

import java.util.Random;
import java.util.Stack;

/** 测试基于数组和链表实现的堆栈的性能   =====>   时间复杂度是在同一个级别的
 * Created by wangbing on 2018/5/3.
 */
public class TestStack {

    public static double testStackDemo(MyStack<Integer> stack, int opCount){
        long startTime = System.nanoTime();
        Random random = new Random();
        for (int i=0;i<opCount;i++){
            stack.push(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i=0;i<opCount;i++){
            stack.pop();
        }
        long endTime = System.nanoTime();
        return (endTime-startTime)/1000-000-000.0;

    }

    public static void main(String[] args) {
        int opCount = 100-000-000;
        ArrayStack<Integer> arrayStack= new ArrayStack<Integer>();
        double  arrayStackTime = testStackDemo(arrayStack,opCount);

        LinkedListStack<Integer> linkedListStack = new LinkedListStack<Integer>();
        double  linkedListStackTime=testStackDemo(linkedListStack,opCount);

        System.out.println("链表栈的时间"+arrayStackTime);
        System.out.println("数组栈的时间"+linkedListStackTime);

    }

}
